import cv2
import os
import numpy as np
def bmpToJpg(file_path, isDelete = True):
    bmpFullname = file_path.replace('.bmp', '.jpg')
    im = cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), cv2.IMREAD_COLOR)  # 读取模板图片
    cv2.imencode('.bmp', im)[1].tofile(bmpFullname)  # 保存图片
    if(isDelete):
        deleteImages(file_path)

def deleteImages(fileFullName):
    command = "del " + fileFullName
    os.system(command)

if __name__ == "__main__":
    imgFolder = r'E:\project\PBroDefectClassification\TxtImg\310-620'
    temp_img = os.listdir(imgFolder)
    total_xml = []
    for img in temp_img:
        if img.endswith(".bmp"):
            total_xml.append(os.path.join(imgFolder, img))
    for p in total_xml:
        bmpToJpg(p)

    print('*****结束****************************************************')